package com.emergency.evaluate.dao;

import com.emergency.evaluate.domain.Extract;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;


import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by Administrator on 2020/3/12.
 */
public interface ExtractDao extends JpaRepository<Extract, String>, JpaSpecificationExecutor<Extract> {
   //提取的指标
    List<Extract> findAllByScenar_id(long scenarId);
   //根据指标ID找到对应指标表
    @Query(value = "select e from Extract e where e.id=:id")
   Extract findAllById(@Param ("id")Long id);

    //根据指标编号删除临时表上的指标
    @Modifying
    @Transactional
    @Query(value = "delete  from Extract e where e.id=:id ")
    void deleteById(@Param ( "id" ) Long id);
    //根据想定删除对应指标表
    @Modifying
    @Transactional
    @Query(value = "delete  from Extract e where scenar.id=:scenarId ")
    void deleteByScenar_id(@Param ( "scenarId" ) Long scenarId);


 //根据指标类型找到对应指标表
 @Query(value = "select e from Extract e where indicator.kind=:kind")
  List<Extract> findAllByKind(@Param ( "kind" ) Integer kind);
}
